package com.zhang.springcloud.app1.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author zhanghaolian
 * @date 2021/6/5 17:53
 */
@Configuration
public class Swagger2Config {
    @Bean
    public Docket myDocket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("controller");

        // 构建apiInfo
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("SWAGGER学习文档")
                .description("仅用于个人学习")
                .contact(new Contact("张先生的开发文档", "https://www.baidu.com", "453192907@qq.com"))
                .version("1.0")
                .build();
        docket.apiInfo(apiInfo);

        // 添加需要扫面的的包以及忽略规则
        docket
                .select()
                .apis(
                        RequestHandlerSelectors.basePackage("com.zhang.springcloud.app1.controller")
                                .or
                        (RequestHandlerSelectors.basePackage("com.zhang.springcloud.api.feignservice"))
                )
                .build();

        return docket;
    }
}
